<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>新增验房单</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/hardware.css">
<link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<!-- <link rel="stylesheet" type="text/css" href="./css/sm.css">
<link rel="stylesheet" type="text/css" href="./css/sm-extend.css"> -->

<script src="../js/jquery-1.8.3.min.js"></script>
<script src="./js/zepto.js"></script>
<script src="./js/sm.js"></script>
<script src="./js/sm-extend.js"></script>
<script type="text/javascript">
window.$$=window.Zepto = Zepto;
</script>
<style>
.check-team{border: 1px solid #d8dcdf;}
.row div{
	border-top: 1px solid #d8dcdf;
	border-right: 1px solid #d8dcdf;
	border-left: 1px solid #d8dcdf;
}
.row{
	border: 1px solid #d8dcdf;
}
.check-team td,th{
	border: 1px solid #d8dcdf;
}
.check-team h5{
	font-size: 14px;
}
</style>
</head>
<body>
	<div class="page">
		<header class="bar bar-nav">
			<a class="button button-link button-nav pull-left" href="javascript:window.history.back();" data-transition='slide-out'>
				<span class="icon icon-left"></span> 返回
			</a>
			<h1 class="title">验房单</h1>
		</header>

	<!-- 主体内容 -->
	<div class="content">
		<div class="D_content--wrap">
			<div id="listItemDiv">
			</div>

			<!-- <div class="list--change-line cl" style="text-align: center;">
				<span id="addItem" style="font-size: 18px;font-weight: 800;" >十</span>
			</div> -->
			<div class="list-remarks">
				<span class="re-txt" style="width:38%">清单所属房屋:</span>&nbsp;&nbsp;
				<select id="houseId" style="width:60%">
				</select>
			</div>
<!-- 			<div class="list-remarks"> -->
<!-- 				<span class="re-txt">房屋地址:</span>&nbsp;&nbsp; -->
<!-- 				<input type="text" class="add-input add-input02" id="houseAddress" placeholder="请输入房屋地址" /> -->
<!-- 			</div> -->
			<div class="list-remarks">
				<span class="re-txt">验房时间:</span>&nbsp;&nbsp;
				<input type="date" id="dealTime" />
			</div>
			<div class="list-remarks">
				<p class="re-txt">备注：</p>
				<textarea id="remark" placeholder="写点什么..."></textarea>
			</div>

			<!-- 保存 -->
			<div class="D_reserve--footer">
				<a href="javascript:toSave();" class="D_reserve--btn">保存</a>
			</div>
		</div>
		
		
	</div>
</div>

<script src="../js/common.js"></script>
<script src="./js/checkList.js"></script>
<script type="text/javascript">
var checkType = $.getUrlParam("checkType");	//0:租客清单 1:业主清单 
var type = 1; 	//1:验房清单清单项
var userId = $.getUrlParam("userId");	//所选租客id或房东id
var listName = $.getUrlParam("listName")||"验房清单";
console.log("userId=="+userId);

$(function(){
// 	$("#houseAddress").val(houseAddress||"");
	checkList.initDefListItem( type ); //加载默认清单项
	checkList.loadHouseList( $("#houseId"), (checkType=="0"?"1":"0") );	//加载可选房子列表
	
	$("#houseId").on("change",function(){
		$("#houseAddress").val($("#houseId").find("option[value="+$(this).val()+"]").attr("data-address"));
	});
	/* // 点击新增清单项
	$("#addItem").on("click",function(){
		var num = $("#listItemDiv").find("span.num").last().text()*1+1;
		var html = '';
		$("#listItemDiv").append(html);
	});
	// 点击删除清单项
	$("#listItemDiv").on("click",".delItem",function(){
		$(this).parent().parent().remove();
		$("#listItemDiv").find("div.list--change-line.cl").each(function(i,n){
			$(n).find("span.num").text(i*1+1);
		 });
	}); */
});


function toSave(){
	if(!$("#houseId").val()){
		$$.toast("请选择房屋");
		return false;
	}
// 	if(!$("#houseId").val()){
// 		$$.toast("请输入房屋地址");
// 		return false;
// 	}
	if(!$("#dealTime").val()){
		$$.toast("请选择验房时间");
		return false;
	}
	
	var checkId = getUUID();	//清单id
	var listItemArr = new Array();
	var num;
	$("#listItemDiv table").each(function(i,n){
		num = $(n).attr("data-num");
		name = $(n).prev("h3").attr("data-name");
		$(n).find("tr[name=data-row]").each(function(j,m){
			var item = {
				itemId : getUUID(),
				checkId : checkId,
				num : num,
				name : name
			};
			item.content = $(m).find("td[name=content]").text()||$(n).find("input.name").val();
			item.method = $(m).find("td[name=method]").text();
			item.result = $(m).find("input[name=result]").val();
			listItemArr.push( item );
		});
	});
	var listItemArrStr = JSON.stringify(listItemArr);
	var listData = {
		checkId : checkId,
		userId : userId,
		houseId : $("#houseId").val(),
		listName : listName,
// 		houseAddress : $("#houseAddress").val(),
		dealTime : $("#dealTime").val(),
		remark : $("#remark").val(),
		checkType : checkType,	//验房清单类型  0:租客 1:业主
		listItemArrStr : listItemArrStr
	}

	checkList.save(listData);
}
</script>
</body>
</html>